<template>
  <el-radio-group @change="handleChange" v-model="checkValue">
    <el-radio v-for="(option, index) in options" :key="index" :label="option.code">
      {{ option.name }}
    </el-radio>
  </el-radio-group>
</template>

<script>
export default {
  props: {
    query: String,
    value: String
  },
  data() {
    return {
      options: [],
      checkValue: this.value
    }
  },
  watch: {
    value(val) {
      this.checkValue = val
    }
  },
  created() {
    if (this.query) {
      this.queryOption(this.query)
    }
  },
  methods: {
    setValue(val) {
      this.checkValue = val
    },
    handleChange(val) {
      this.$emit("input", val)
    },
    queryOption(api) {
      this.$ajax.get(api, {}).then((res) => {
        this.options = res.data
      })
    }
  }
}
</script>
<style lang="less"></style>
